package com.hundsun.cprs.yyt.service.account.service.impl;

import java.util.List;

import com.hundsun.cprs.yyt.service.account.dto.AccountQuotaLogInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hundsun.cprs.yyt.common.base.BaseService;
import com.hundsun.cprs.yyt.service.account.dao.AccountQuotaLogDao;
import com.hundsun.cprs.yyt.service.account.domain.AccountQuotaLog;
import com.hundsun.cprs.yyt.service.account.domain.query.AccountQuotaLogQuery;
import com.hundsun.cprs.yyt.service.account.service.AccountQuotaLogService;

@Service
public class AccountQuotaLogServiceImpl extends BaseService implements AccountQuotaLogService {
    
    @Autowired
    private AccountQuotaLogDao accountQuotaLogDao;

    @Override
    public void selectByPage(AccountQuotaLogQuery query) {
        List<AccountQuotaLogInfo> result = accountQuotaLogDao.selectByQuery(query);
        query.compatible(result);
    }

    @Override
    public List<AccountQuotaLogInfo> selectByList(AccountQuotaLogQuery query) {
        query.onlyReturnList();
        return accountQuotaLogDao.selectByQuery(query);
    }

    @Override
    public AccountQuotaLog log(AccountQuotaLog accountQuoatLog) {
        accountQuotaLogDao.insert(accountQuoatLog);
        return accountQuoatLog;
    }

    @Override
    public Long getDaliyUserUsedQuoteAmount(AccountQuotaLogQuery query) {
        Long amount = 0L;
        List<AccountQuotaLogInfo> accountQuotaLogList = this.selectByList(query);
        if (!accountQuotaLogList.isEmpty()){
            for (AccountQuotaLogInfo accountQuotaLog:accountQuotaLogList){
                amount += accountQuotaLog.getTransAmount();
            }
        }
        return amount;
    }
}
